package com.huaxin.hxcloud.activity;

import android.content.Context;
import android.support.annotation.DrawableRes;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.huaxin.common.Entity.HxScStaionListBean;
import com.huaxin.common.Entity.HxStaionListBean;
import com.huaxin.hxcloud.R;

/**
 * @author songxf
 * @date 2018/5/15
 * @Desc 站点列表
 */
public class HxStationListAdapter extends BaseQuickAdapter<HxScStaionListBean.StationListBean, BaseViewHolder> {

    private HxStationListActivity mHxStationListActivity;
    private Context               mContext;

    public HxStationListAdapter(HxStationListActivity hxStationListActivity) {
        super(R.layout.item_station_new);
        this.mHxStationListActivity = hxStationListActivity;
        this.mContext = hxStationListActivity;
    }

    @Override
    protected void convert(BaseViewHolder helper, HxScStaionListBean.StationListBean item) {
        TextView mStationName = helper.getView(R.id.stationName);
        TextView mbuildAddress = helper.getView(R.id.buildAddress);
        TextView mOwnerName = helper.getView(R.id.ownerName);
        mOwnerName.setText(("负责人：" + item.getContactPerson()));
        mbuildAddress.setText(item.getAddress());

        for (int i = 0; i < item.getDeviceList().size(); i++) {
            HxScStaionListBean.StationListBean.DeviceListBean deviceListBean = item.getDeviceList().get(i);
            mHxStationListActivity.loadNetImg((ImageView) helper.getView(R.id.img), deviceListBean.getImgUrl());
        }
        mStationName.setText(("地址：" + item.getStationName()));

        TextView phone = helper.getView(R.id.phone);
        phone.setText(item.getContactPhone());
        setStateText((TextView) helper.getView(R.id.state_tv), item.getStationState());
    }

    private void setStateText(TextView textView, int state) {
        int static_normal = mContext.getResources().getColor(R.color.text_color_f);
        int static_timeout = mContext.getResources().getColor(R.color.red_checked);
        int static_out = mContext.getResources().getColor(R.color.color_fb9846);
        //站点状态 0:正常，1：通讯超时，2、故障，3、待初始化
        textView.setVisibility(View.VISIBLE);
        switch (state) {
            case 0:
                setTextViewBackgroundResource("正常", textView, R.drawable.bg_normal_green, static_normal);
                break;
            case 1:
                setTextViewBackgroundResource("超时", textView, R.drawable.bg_timeout_state, static_timeout);
                break;
            case 2:
                setTextViewBackgroundResource("故障", textView, R.drawable.bg_trouble_state, static_out);
                break;
            case 3:
                setTextViewBackgroundResource("待初始化", textView, R.drawable.bg_trouble_state, static_out);
                break;
            default:
                setTextViewBackgroundResource("未知", textView, R.drawable.bg_normal_green, static_normal);
                break;
        }
    }

    private void setTextViewBackgroundResource(String content, TextView textView, @DrawableRes int drawable, int color) {
        textView.setText(content);
        textView.setTextColor(color);
        textView.setBackgroundResource(drawable);
    }

}
